package models.dao;

import java.sql.ResultSet;
import java.util.ArrayList;

import model.pojo.Terms;
import model.util.MySqlDataAccessHelper;

public class TermDAO {

	public ArrayList<Terms> oneterm(String id){
		ArrayList<Terms> lst = new ArrayList<Terms>();
		MySqlDataAccessHelper mysql = new MySqlDataAccessHelper();
		try{
			mysql.open();
			String ten="DescrVN";
			String sql ="select TermsID,"+ten+" from terms where TermsID='"+id+"'";
			ResultSet rs=mysql.executeQuery(sql);
			Terms cg;
			while(rs.next()){
				cg = new Terms();
				cg.setTermsID(rs.getString("TermsID"));
				cg.setUsename(rs.getString(ten));
			}
			rs.close();
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			mysql.close();
		}
		return lst;
	}
	
	public ArrayList<Terms> termslst(){
		ArrayList<Terms> lst = new ArrayList<Terms>();
		MySqlDataAccessHelper mysql = new MySqlDataAccessHelper();
		try{
			mysql.open();
			String ten="DescrVN";
			String sql ="select TermsID,"+ten+" from terms";
			ResultSet rs=mysql.executeQuery(sql);
			Terms cg;
			while(rs.next()){
				cg = new Terms();
				cg.setTermsID(rs.getString("TermsID"));
				cg.setUsename(rs.getString(ten));
			}
			rs.close();
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			mysql.close();
		}
		return lst;
	}
}
